package com.example.forum_system.controller;

import com.example.forum_system.common.Result;
import com.example.forum_system.common.ResultCode;
import com.example.forum_system.service.IArticleService;
import com.example.forum_system.service.IBoardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongsProject: 0.forum_system
 * @BelongsPackage: com.example.forum_system.controller
 * @Author : 游在海里的鱼
 * @CreateTime : 2023-11-12  20:37
 * @Version : 1.0
 * @Description : TODO
 */
@Slf4j
@RestController
@RequestMapping("/board")
public class BoardController {
    @Autowired
    IBoardService boardService;

    @Autowired
    IArticleService articleService;

    @GetMapping("/getBoard")
    public Result getBoard(){
        return Result.success(boardService.selectByNum());
    }

    @PostMapping("/getCount")
    public Result getCount(Long boardId){
        if(boardId==null || boardId<0){
            log.warn("获取板块文章数时，传入板块id无效");
            return Result.failed(ResultCode.FAILED_PARAMS_VALIDATE);
        }
        return Result.success(articleService.selectArticleCountBoard(boardId));
    }
}
